﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;

namespace WebAPI.Controllers
{
    public class downfileController : ApiController
    {
       // public static string filname_a = "Flie";
       // FileInfo fileInfo = new FileInfo(filname_a);
        public HttpResponseMessage Get(string filename)
        {

            var path = System.Web.HttpContext.Current.Server.MapPath($"~/Flie/{filename}");
            // var orighinName = "class1.cs";
            HttpResponseMessage result = new HttpResponseMessage(HttpStatusCode.OK);
            var stream = new FileStream(path, FileMode.Open);
            result.Content = new StreamContent(stream);
            result.Content.Headers.ContentDisposition = new System.Net.Http.Headers.ContentDispositionHeaderValue("attachment");
            //FileName = orighinName;
            result.Content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/octet-stream");
            result.Content.Headers.ContentLength = stream.Length;
            return result;
        }
    }
}
